<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>已买到商品</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
</head>
<style type="text/css">
    body {
        font-size: 14px;
    }

    .aui-content-padded {
        margin: 0 10px;
        padding: 10px 0;
    }

    .addFriend.aui-border:after {
        border-color: #327afa;
    }

    .orderList {
        margin-bottom: 15px;
    }

    .proTitle {
        font-size: 14px;
        line-height: 17px;
        color: #666;
    }

    .proTitleP {
        margin: 8px 0 !important;
        color: #000;
    }

    .proList.aui-list-view .aui-img-object {
        max-width: 70px;
        height: 70px;
        line-height: 70px;
    }

    .orderTitle {
        font-size: 14px;
        padding: 0 12px;
        background: #fff;
        height: 42px;
        line-height: 42px;
    }

    .proPrice {
        text-align: right;
        margin-top: 5px;
    }

    .proList.aui-list-view {
        margin: 0;
    }

    .aui-list-view:after {
        border: none;
    }

    .totalPrice {
        font-size: 18px;
    }

    .proFooter .aui-list-view-cell {
        text-align: right;
    }

    .proMoreHandle {
        overflow: inherit;
        height: 55px;
        padding-right: 1px;
    }

    .proMoreHandle span {
        float: right;
        display: block;
        padding: 5px 8px;
        border-radius: 3px;
        margin-right: 8px;
    }

    .proMoreHandle span.active.aui-border:after {
        border-color: #327afa;
    }

    .proMoreHandle .aui-border:after {
        border-radius: 5px;
    }

    .more {
        position: relative;
        /*margin-right: 0 !important;*/
    }

    .more a {
        /*color: #000;*/
        color: #666;
        font-size: 13px;
    }

    .moreList {
        /*left: -28px;*/
        background: #FFF;
        border-radius: 5px;

    }

    .moreList li {
        padding: 5px 8px;
        width: 100px;
        text-align: center;
    }

    .mui-popover {
        width: 100px;
    }

    .active {
        background: #327afa !important;
        color: #fff !important;
        overflow: hidden;
    }

    /*下面弹出的样式*/
    .pickerToTop {
        position: fixed;
        bottom: 0;
        -webkit-transform: translateY(195px);
        height: 195px;
        overflow-y: auto;
        -webkit-transition: .5s;
        transition: .5s;
        z-index: 999;
        width: 100%;
        text-align: center;
    }

    .toTopAnimate {
        -webkit-transform: translateY(00px);
    }

    .grayColor {
        color: #aaa;
    }
</style>
<body>
<div class="kongshuju">
    <p>暂无数据</p>
</div>
<div class="contain orderLists" id="orderList-content">


    <!-- 等待买家付款 -->
    <!--<div class="orderList">-->
    <!--<div class="orderTitle myBorder">-->
    <!--<span class="comName">苏州市素絮服饰有限公司2222</span>-->
    <!--<span class="orderStatus zfBlue aui-pull-right">等待买家付款</span>-->
    <!--</div>-->
    <!--<ul class="aui-list-view proList" tapmode onclick="openToTwo('orderInfo')">-->
    <!--<li class="aui-list-view-cell aui-img">-->
    <!--<img class="aui-img-object aui-pull-left" src="../image/shili.jpg">-->

    <!--<div class="aui-img-body proTitle  aui-col-xs-6">-->
    <!--<p class="aui-ellipsis-2 proTitleP">图文列表缩略图在左边的样式，默认大小为80PX，文字介绍内容可以为一行也可以为两行，超出部分自动省略</p>-->
    <!--<span class="proColor">藏青</span>-->
    <!--<span class="proSize">均码</span>-->
    <!--</div>-->

    <!--<div class="aui-img-body proPrice">-->
    <!--<span>￥53.60</span>-->

    <!--<p>x1</p>-->
    <!--</div>-->
    <!--</li>-->
    <!---->
    <!--</ul>-->
    <!--<div class="proFooter">-->
    <!--<ul class="aui-list-view">-->
    <!--<li class="sendLink aui-list-view-cell">-->
    <!--共2件 总金额:￥<span class="totalPrice">107.20</span>(含运费 ￥10.00)-->
    <!--</li>-->
    <!--<li class="aui-list-view-cell proMoreHandle">-->
    <!--<span class="aui-border active">付款</span>-->
    <!--<span class="aui-border">取消订单</span>-->
    <!--<span class="more">-->
    <!--&lt;!&ndash; 这个a锚点链接对应下面的id ，后面可以加上订单的id&ndash;&gt;-->
    <!--<a href="#bottomPopover">更多</a>-->
    <!--</span>-->
    <!--</li>-->
    <!--</ul>-->
    <!--</div>-->
    <!--</div>-->
</div>
<script id="orderList-template" type="text/x-dot-template">
    {{ for (var i in it) { }}
    <div class="orderList" id="order{{=it[i].order_id}}" tapmode>
        <div class="orderTitle myBorder">
            <span class="comName">{{=it[i].referer}}</span>
            <span class="orderStatus grayColor aui-pull-right">
                {{?it[i].froms!="qrcode"}}
                    {{? it[i].status == 0}}交易关闭
                    {{?? it[i].status == -1}}商品下架
                    {{?? it[i].status == 1}}<span class="zfBlue">等待付款</span>
                    {{?? it[i].status == 2}}已取消
                    {{?? it[i].status == 3}}已付款
                    {{?? it[i].status == 4}}已发货
                    {{?? it[i].status == 5}}已收货
                    {{?? it[i].status == 6}}<span class="aui-text-danger">申请退款</span>
                    {{?? it[i].status == 7}}<span class="aui-text-danger">申请退货</span>
                    {{?}}
                {{??}}
                <span class="aui-text-danger">线下扫码付款</span>
                {{?}}
            </span>
        </div>
        <ul class="aui-list-view proList" tapmode orderStatus="{{=it[i].status}}" orderId="{{=it[i].order_id}}"
            onclick="openOrderInfo(this)">
            <!--线下扫码付款-->
            {{?it[i].froms=="qrcode"}}
            <li class="aui-list-view-cell aui-img">
                <div class="aui-img-body proTitle  aui-col-xs-6">
                    <p class="aui-ellipsis-2 proTitleP">用户<em class="aui-text-danger">{{=it[i].mobile}}</em>已付款</p>
                </div>

                <div class="aui-img-body proPrice">
                    <span>￥{{=it[i].goods_amount}}</span>

                </div>
            </li>
            {{??}}
            <!--购买商品列表-->
            {{ for (var is in it[i].goods) { }}
            <li class="aui-list-view-cell aui-img">
                <img class="aui-img-object aui-pull-left" src="{{=it[i].goods[is].goods_info.goods_thumb}}">

                <div class="aui-img-body proTitle  aui-col-xs-6">
                    <p class="aui-ellipsis-2 proTitleP">{{=it[i].goods[is].goods_name}}</p>
                    <span class="proColor">{{=it[i].goods[is].goods_attr}}</span>
                </div>

                <div class="aui-img-body proPrice">
                    <span>￥{{=it[i].goods[is].goods_price}}</span>

                    <p>x{{=it[i].goods[is].goods_number}}</p>
                </div>
            </li>
            {{ } }}
            {{?}}

        </ul>
        <div class="proFooter">
            <ul class="aui-list-view">
                <li class="sendLink aui-list-view-cell" style="color:#666;font-size: 13px;">
                    {{?it[i].froms!="qrcode"}}
                    共{{=it[i].rebate_ispay}}件 总金额：(含运费 ￥{{=it[i].shipping_fee}}) &nbsp;
                    {{??}}
                    <div class="aui-pull-left" style="height: 24px;line-height: 24px;">下单时间&nbsp;<em class="addTime">{{=it[i].add_time}}</em>
                    </div>
                    {{?}}
                    <span class="totalPrice aui-text-danger">￥{{=it[i].goods_amount}}</span>
                </li>
                <!--未付款-->
                {{?it[i].froms!="qrcode"}}
                {{? it[i].status == 1}}
                <li class="aui-list-view-cell proMoreHandle zfBlue" id="proMoreHandle{{=it[i].order_id}}">
                    <span class="aui-border active " tapmode orderStatus="{{=it[i].status}}"
                          orderId="{{=it[i].order_id}}" onclick="goToPay(this)">确认付款</span>
                    <!--<span class="aui-border" onclick="cancellationOrder({{=it[i].order_id}})">取消订单</span>-->
                    <span class="more">
                           </span>
                </li>
                <!--取消-->
                {{?? it[i].status == 2}}
                <li class="aui-list-view-cell proMoreHandle aui-text-default">
                    <span class="aui-border" onclick="deleteOrder({{=it[i].order_id}})">删除订单</span>
                </li>


                <!--已付款-->
                {{?? it[i].status == 3}}
                <li class="aui-list-view-cell proMoreHandle aui-text-danger">
                    <span class="aui-border" data-orderId="{{=it[i].order_id}}"
                          data-sellerName="{{=it[i].mobile}}"
                          onclick="reminderDelivery(this)">提醒发货</span>
                </li>

                <!--已发货-->
                {{?? it[i].status == 4}}

                <li class="aui-list-view-cell proMoreHandle zfBlue" id="proMoreHandle{{=it[i].order_id}}">
                    <span class="aui-border active" onclick="confirmReceipt({{=it[i].order_id}})">确认收货</span>
                    <span class="aui-border" tapmode onclick="openWuLiu('{{=it[i].mobile}}')">查看物流</span>

                </li>
                <!--已收货-->
                <!--{{?? it[i].status == 5}}-->
                <!--<li class="aui-list-view-cell proMoreHandle zfBlue">-->
                <!--<span class="aui-border active" tapmode orderId="{{=it[i].order_id}}"-->
                <!--goodsId="{{=it[i].goods[0].order_id}}" onclick="goToEvaluate(this)">追加评论</span>-->
                <!--<span class="aui-border" tapmode onclick="openWuLiu('{{=it[i].order_id}}')">查看物流</span>-->

                <!--</li>-->
                <!--交易关闭-->
                {{?? it[i].status <= 0}}
                <li class="aui-list-view-cell proMoreHandle aui-text-default">
                    <span class="aui-border" onclick="deleteOrder({{=it[i].order_id}})">删除订单</span>
                </li>
                {{?}}
                {{?}}
            </ul>

        </div>
    </div>
    {{ } }}
</script>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/jquery-1.11.3.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript">
    var page = 1, isLock = false, status = 0, myOrderId;
    apiready = function () {

        myAvatar = $api.getStorage('avatar');
        targetId = api.pageParam.targetId;
        targetAvatar = api.pageParam.targetAvatar;
        targetNickname = api.pageParam.targetNickname;
        api.parseTapmode();
        if (api.pageParam.status) {
            status = api.pageParam.status;
        }
        //重新加载缓存
        getStorageAll();

        //接收监听
        api.addEventListener({
            name: 'orderStatus'
        }, function (ret) {
            if (ret && ret.value) {
                isLock = false;
                page = 1;
                $("#orderList-content").empty();
                status = ret.value.status
//                api.refreshHeaderLoading();
                orderList(status, page);
            }
        });

        //接收监听
        api.addEventListener({
            name: 'makeSureGetPro'
        }, function (ret) {
            if (ret && ret.value) {
                page = 1;
                //我的页面更新订单数
                isLock = false;
                updateOrderNum();
                api.refreshHeaderLoading();
                return false;
            }
        });
        //接收订单详情页的用户删除订单等操作更新订单数量
        api.addEventListener({
            name: 'updateOrderNum'
        }, function (ret) {
            if (ret && ret.value) {
                isLock = false;
                api.refreshHeaderLoading();
            }
        });
        //我的页面更新订单数

        //接收监听支付密码
        api.addEventListener({
            name: "hasPass"
        }, function (ret) {
            if (ret && ret.value.pass) {
                confirmLoad(ret.value.orderId);
            }
        })
        orderList("");
//        api.setRefreshHeaderInfo({
//            visible: true,
//            loadingImg: 'widget://image/ptr_pull.png',
//            bgColor: '#efeff4',
//            textColor: '#959595',
//            textDown: '下拉刷新',
//            textUp: '松开刷新',
//            showTime: true
//        }, function (ret, err) {
//            isLock = false;
//            page = 1;
//            orderList("");
//        });
        //监听是否达到底部上拉加载7
        api.addEventListener({
            name: 'scrolltobottom'
        }, function (ret, err) {
            page++;
            if (!isLock) orderList(status, page);
        });

//        api.refreshHeaderLoading();
    }


    //订单列表
    function orderList(status, toPage) {
        if (isLock)return;

//        toPage = toPage ? toPage : page;
//        if (toPage == 1) api.refreshHeaderLoading();
        data = {
            page: page,
            status: status
        };
        url = "order/list";
        isLock = true;
        ajaxRequest(url, 'get', data, function (ret, err) {
            api.refreshHeaderLoadDone();
            isLock = false;
            var content = $api.byId('orderList-content');
            var tpl = $api.byId('orderList-template').text;
            var tempFn = doT.template(tpl);
//            alert(ret.data[0]["order_id"])
            if (page > 1) {
                if (!$.trim(ret.data)) {
                    isLock = true;
                    return;
                }
                $api.append(content, tempFn(ret.data));
            } else {
                showNoTip(ret.data)
                $api.html(content, tempFn(ret.data));
            }
            $("#orderList-content").find(".addTime").each(function () {
                $(this).text(stampToTime($(this).text()))
            })
        });
    }
    function openOrderInfo(obj) {
        return false;
        var orderId = $(obj).attr("orderId");
        var orderStatus = $(obj).attr("orderStatus");
        api.openWin({
            name: 'orderInfo_win',
            url: 'orderInfo_win.html',
            pageParam: {
                orderId: orderId,
                orderStatus: orderStatus
            },
            //delay: 300
        });

    }

    //取消订单
    function cancellationOrder(orderId) {
        if (confirm('确定取消吗')) {
            //订单关闭
            showLoading();
            data = {
                userName: user_name,
                orderId: orderId,
            };
            url = "User/cancellationOrder";
            ajaxRequest(url, 'post', data, function (ret, err) {
                if (ret.status == 1) {
                    api.toast({
                        msg: '修改订单成功',
                        duration: 2000,
                        location: 'bottom'
                    });
                    if (status == 1) {

                        //我的页面更新订单数
                        updateOrderNum();
                        $("#order" + orderId).hide();
                    } else {
                        $('.aui-pull-right').text('交易关闭');
                        $('#proMoreHandle' + orderId).html("<span class='aui-border' onclick='deleteOrder(" + orderId + ")'>删除订单</span>");
                    }
                } else {
                    api.toast({
                        msg: '修改订单失败',
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
            hideLoading();
        }
    }

    //删除订单
    function deleteOrder(orderId) {
        if (confirm('确定删除吗')) {
            //订单关闭
            showLoading();
            data = {
                userName: user_name,
                orderId: orderId,
            };
            url = "User/deleteOrder";
            ajaxRequest(url, 'post', data, function (ret, err) {
                if (ret.status == 1) {
                    api.toast({
                        msg: '删除订单成功',
                        duration: 2000,
                        location: 'bottom'
                    });
                    //我的页面更新订单数
                    updateOrderNum();


                    $("#order" + orderId).hide();
                } else {
                    api.toast({
                        msg: '删除订单失败',
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
            hideLoading();
        }
    }

    //提醒发货
    function reminderDelivery(obj) {
        var orderId = $(obj).attr('data-orderId');
        var tourser = $(obj).attr('data-sellerName');
        if (confirm('确定提醒吗')) {
            //订单关闭
            showLoading();
            data = {
                userName: user_name,
                orderId: orderId,
                touser: tourser,
            };
            url = "User/sendMessage";
            ajaxRequest(url, 'post', data, function (ret, err) {
                if (ret.status == 1) {
                    api.toast({
                        msg: ret.msg,
                        duration: 2000,
                        location: 'bottom'
                    });
                } else {
                    api.toast({
                        msg: ret.msg,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
            hideLoading();
        }
    }

    //确认收货
    function confirmReceipt(orderId) {
        api.openFrame({
            bgColor: 'rgba(0,0,0,0.6)',
            name: 'passWord',
            url: 'passWord.html',
            bounces: false,
            rect: {
                x: 0,
                y: 0,
                w: 'auto',
                h: 'auto'
            },
            pageParam: {
                orderId: orderId
            }
        });
    }
    function confirmLoad(orderId) {
//        订单确认收货
        showLoading();
        data = {
            userName: user_name,
            orderId: orderId,
        };
        url = "User/confirmReceipt";
        ajaxRequest(url, 'post', data, function (ret, err) {
            if (ret.status == 1) {

//                    }
                updateOrderNum();
                api.toast({
                    msg: "已确认收货",
                    duration: 2000,
                    location: 'bottom'
                });
            } else {
                api.toast({
                    msg: ret.msg,
                    duration: 2000,
                    location: 'bottom'
                });
            }
        });
        hideLoading();

    }
    function goToPay(obj) {

        var orderId = $(obj).attr("orderId");
        var orderStatus = $(obj).attr("orderStatus");


        api.actionSheet({
            title: "选择支付方式",
            // buttons: ['微信(推荐)', "支付宝"]
            buttons: ['微信']
        }, function (ret, err) {

            if (ret.buttonIndex == 1) {
                // openToTwo(urlContent+"popInputWxPay_win")
                payOfOrderId(orderId)
            } else {
                return false;
            }
        });
    }
    function payOfOrderId(orderId) {
        var getPayOrderIdUrl = "order/payparam";
        var dataOrder = {};
        dataOrder["order_id"] = orderId;
        ajaxRequest(getPayOrderIdUrl, 'get', dataOrder, function (ret, err) {
            var appid = ret.data.appid;
            var noncestr = ret.data.noncestr;
            var package = ret.data.package;
            var partnerid = ret.data.partnerid;
            var prepayid = ret.data.prepayid;
            var sign = ret.data.sign;
            var timestamp = ret.data.timestamp;
            wxpay(appid, noncestr, package, partnerid, prepayid, sign, timestamp,"updateOrderList");
            //订单充值未空
        })
    }
</script>
</html>